/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entity;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import model.Action;

import model.entityTable;
import sql.AConnection;

/**
 *
 * @author aragon
 */
public class DetailRoomE extends AConnection implements entityTable<DetailRoomE>{
    private String idDRM;
    private String idRoom;
    private String roomName;
    private String idDate;
    private String date;
    private String period;
    private String idLocal;
    private String localName;
    private String content;
    private String roomSize;
    private String weed;
    private String day;


    public boolean select() {
        try {
            String query = "SELECT NoiDung,ngay,Tuan,thu,tiet," 
                    + "TenPhong,chitietphong.idTG,SucChua,TenKhu,khuvuc.idKhu  FROM phonghoc,"
                    + "chitietphong,thoigian,khuvuc where idCTPhong=? "
                    + "and chitietphong.idTG=thoigian.idTG && "
                    + "chitietphong.idPhong=phonghoc.idPhong && " 
                    + "phonghoc.idKhu=khuvuc.idKhu && chitietphong.AnHien =1";
            Connection connection = getConnection();
            PreparedStatement ps = connection.prepareStatement(query);
            ps.setString(1, idDRM);
            ResultSet rs= ps.executeQuery();
            if(rs.next()){
                roomName=rs.getString("TenPhong");
                idDate=rs.getString(7);
                date=rs.getString("ngay");
                period=rs.getString("tiet");
                idLocal=rs.getString(10);
                localName=rs.getString("TenKhu");
                content=rs.getString("NoiDung");
                roomSize=rs.getString("SucChua");
                weed=rs.getString("Tuan");
                day=rs.getString("thu") ;
                return  true;
            }else{
                return false;
            }
        } catch (SQLException ex) {
            return  false;
        }
    }

    public ResultSet selectDB() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean insert() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean update() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean remove() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    public boolean checkRoom(){
       try {
            String query = "SELECT NoiDung FROM chitietphong,thoigian"
                    + " WHERE chitietphong.idTG=thoigian.idTG and "
                    + "thoigian.ngay= ? and  chitietphong.idPhong = ?"
                    + " and thoigian.tiet=?";
            Connection connection = getConnection();
            PreparedStatement ps = connection.prepareStatement(query);
            ps.setString(1, Action.converDatetoMysql(getDate()));
            ps.setString(2, getIdRoom());
            ps.setString(3, getPeriod());
            ResultSet rs= ps.executeQuery();
            if(rs.next()){
                if(rs.getString("NoiDung").equals("0")){
                return true;}else{
                    return false;
                }
            }else{
                return false;
            }
        } catch (SQLException ex) {
            return false;
        }
    }

    public String getIdDRM() {
        return idDRM;
    }

    public void setIdDRM(String idDRM) {
        this.idDRM = idDRM;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getIdDate() {
        return idDate;
    }

    public void setIdDate(String idDate) {
        this.idDate = idDate;
    }

    public String getIdLocal() {
        return idLocal;
    }

    public void setIdLocal(String idLocal) {
        this.idLocal = idLocal;
    }

    public String getLocalName() {
        return localName;
    }

    public void setLocalName(String localName) {
        this.localName = localName;
    }

    public String getRoomName() {
        return roomName;
    }

    public void setRoomName(String roomName) {
        this.roomName = roomName;
    }

    public String getWeed() {
        return weed;
    }

    public void setWeed(String weed) {
        this.weed = weed;
    }

    public String getDay() {
        return day;
    }

    public void setDay(String day) {
        this.day = day;
    }

    public String getRoomSize() {
        return roomSize;
    }

    public void setRoomSize(String roomSize) {
        this.roomSize = roomSize;
    }

    public String getPeriod() {
        return period;
    }

    public void setPeriod(String period) {
        this.period = period;
    }

    public String getIdRoom() {
        return idRoom;
    }

    public void setIdRoom(String idRoom) {
        this.idRoom = idRoom;
    }


    

}
